package day5;

import java.util.Scanner;

import org.junit.Test;

public class StudentManager {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生数量");
		int count = scanner.nextInt();
		Student[] students = new Student[count];
		for (int i = 0; i < students.length; i++) {
			System.out.println("请输入学生id：");
			int id = scanner.nextInt();
			System.out.println("请输入学生姓名：");
			scanner.nextLine();
			String name = scanner.next();
			System.out.println("请输入学生年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入学生性别：");
			String gender = scanner.next();
			Student student = new Student(id, name, age, gender);
			students[i] = student;
		}
		// 1.用户搜索完了之后可以不停的搜索
		// 2.搜索过程中有这个学生年龄信息，就打印这个对象信息
		// 3.如果搜索完了之后，没有找到符合条件的学生信息，就打印“没有该信息的学生”
		while (true) {
			System.out.println("----------------------------");
			System.out.println("输入1，按id搜索");
			System.out.println("输入2，按年龄搜索");
			System.out.println("输入3，按名字搜索");
			System.out.println("输入4，按性别搜索");
			System.out.println("输入0，退出");
			System.out.println("----------------------------");
			int type = scanner.nextInt();
			if (type == 0) {
				System.out.println("退出程序");
				break;
			}
			
			// boolean isSearchFound = false;
			switch (type) {
			case 1:
				System.out.println("请输入您要查找的id：");
				int id = scanner.nextInt();
				// 初始认为根据id没有找到这个学生，因为还没有开始找，所以初始没有找到
				boolean isSearchByIdFound = false;
				for (int i = 0; i < students.length; i++) {
					if (id == students[i].getId()) {
						System.out.println(students[i]);
						isSearchByIdFound = true;
					}
				}
//				if (!isSearchByIdFound) {
//					
//				}
				if (isSearchByIdFound == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 2:
				System.out.println("请输入您要查找的年龄：");
				int age = scanner.nextInt();
				boolean isSearchByAgeFound = false;
				for (int i = 0; i < students.length; i++) {
					if (age == students[i].getAge()) {
						System.out.println(students[i]);
						isSearchByAgeFound = true;
					}
				}
				if (isSearchByAgeFound == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 3:
				System.out.println("请输入您要查找的名字：");
				String name = scanner.next();
				boolean isSearchByNameFound = false;
				for (int i = 0; i < students.length; i++) {
					Student student = students[i];
					// equal是比较字符串的内容是不是相等
					if (name.equals(student.getName())) {
						System.out.println(students[i]);
						isSearchByNameFound = true;
					}
				}
				if (isSearchByNameFound == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 4:
				System.out.println("请输入您要查找的性别：");
				String gender = scanner.next();
				boolean isSearchByGenderFound = false;
				for (int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (gender.equals(student.getGender())) {
						System.out.println(students[i]);
						isSearchByGenderFound = true;
					}
				}
				if (isSearchByGenderFound == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			default:
				break;
			}
		}
		scanner.close();
	}
	
	@Test
	public void test1() {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		System.out.println(str);
	}
}
